<?php

/**

 * 积分管理

 *

 *

 * @网店运维提供技术支持 授权请购买shopnc授权

 * @license    http://www.shopwwi.com

 * @link       交流群号：111731672

 */







defined('ByShopWWI') or exit('Access Invalid!');

class pointsredControl extends SystemControl{

    const EXPORT_SIZE = 5000;

    public function __construct(){

        parent::__construct();

        Language::read('points');

        //判断系统是否开启积分功能

        if (C('points_isuse') != 1){

            showMessage(Language::get('admin_points_unavailable'),'index.php?act=setting','','error');

        }

    }


   /**

     * 积分日志列表

     */

    public function pointslogOp(){

		Tpl::setDirquna('shop');/*网 店 运 维shop wwi.com*/

        Tpl::showpage('points.log');

    }
	//宝豆
    public function pointsredlogOp(){

		Tpl::setDirquna('shop');/*网 店 运 维shop wwi.com*/

        Tpl::showpage('pointsred.log');

    }
	//库存积分
    public function pointskucunlogOp(){

		Tpl::setDirquna('shop');/*网 店 运 维shop wwi.com*/

        Tpl::showpage('pointskucun.log');

    }	




    /**

     * 输出XML数据

     */

    public function get_xmlOp() {

        $condition = array();

        if ($_POST['query'] != '') {

            $condition[$_POST['qtype']] =  $_POST['query'];

        }

        $order = '';

        $param = array('pl_id','pl_memberid','pl_membername','pl_points','pl_addtime');

        if (in_array($_POST['sortname'], $param) && in_array($_POST['sortorder'], array('asc', 'desc'))) {

            $condition['order'] = $_POST['sortname'] . ' ' . $_POST['sortorder'];

        }

        $page   = new Page();

        $page->setEachNum(!empty($_POST['rp']) ? intval($_POST['rp']) : 15);

        $page->setStyle('admin');

        $points_model = Model('points');

        $list_log = $points_model->getPointsLogList($condition,$page,'*','');

		if (empty($list_log)) $list_log = array();

        $stage_arr = $this->get_state();

        $data = array();

        $data['now_page'] = $page->get('now_page');;

        $data['total_num'] = $page->get('total_num');

        foreach ($list_log as $value) {

            $param = array();

            $param['operation'] = "--";

            $param['pl_id'] = $value['pl_id'];

            $param['pl_memberid'] = $value['pl_memberid'];

            $param['pl_membername'] = $value['pl_membername'];

            $param['pl_points'] = $value['pl_points'];

			$param['pl_stage'] = $stage_arr[$value['pl_stage']];

			$param['pl_addtime'] = date('Y-m-d H:i:s', $value['pl_addtime']);

            $param['pl_desc'] = $value['pl_desc'];

            $param['pl_adminname'] = $value['pl_adminname'];

            $data['list'][$value['pl_id']] = $param;

        }

        echo Tpl::flexigridXML($data);exit();

    }
	//分红豆明细
public function getred_xmlOp() {

        $condition = array();

        if ($_POST['query'] != '') {

            $condition[$_POST['qtype']] =  $_POST['query'];

        }

        $order = '';

        $param = array('pl_id','pl_memberid','pl_membername','pl_points','pl_addtime');

        if (in_array($_POST['sortname'], $param) && in_array($_POST['sortorder'], array('asc', 'desc'))) {

            $condition['order'] = $_POST['sortname'] . ' ' . $_POST['sortorder'];

        }

        $page   = new Page();

        $page->setEachNum(!empty($_POST['rp']) ? intval($_POST['rp']) : 15);

        $page->setStyle('admin');

        $points_model = Model('points');

        $list_log = $points_model->getPointsLogList($condition,$page,'*','');

		if (empty($list_log)) $list_log = array();

        $stage_arr = $this->getred_state();

        $data = array();

        $data['now_page'] = $page->get('now_page');;

        $data['total_num'] = $page->get('total_num');

        foreach ($list_log as $value) {

            $param = array();

            $param['operation'] = "--";

            $param['pl_id'] = $value['pl_id'];

            $param['pl_memberid'] = $value['pl_memberid'];

            $param['pl_membername'] = $value['pl_membername'];

            $param['pl_points'] = $value['pl_points'];

			$param['pl_stage'] = $stage_arr[$value['pl_stage']];

			$param['pl_addtime'] = date('Y-m-d H:i:s', $value['pl_addtime']);

            $param['pl_desc'] = $value['pl_desc'];

            $param['pl_adminname'] = $value['pl_adminname'];

            $data['list'][$value['pl_id']] = $param;

        }

        echo Tpl::flexigridXML($data);exit();

    }


    private function get_state() {

        $array = array();

        $array['regist'] = L('admin_points_stage_regist');

        $array['login'] = L('admin_points_stage_login');

        $array['comments'] = L('admin_points_stage_comments');

        $array['order'] = L('admin_points_stage_order');

        $array['system'] = L('admin_points_stage_system');

        $array['pointorder'] = L('admin_points_stage_pointorder');

        $array['app'] = L('admin_points_stage_app');

        return $array;

    }
	//宝豆
    private function getred_state() {

        $array = array();

        $array['regist'] = L('admin_points_stage_regist');

        $array['login'] = L('admin_points_stage_login');

        $array['comments'] = L('admin_points_stage_comments');

        $array['order'] = L('admin_points_stage_order');

        $array['system'] = L('admin_points_stage_system');

        $array['pointorder'] = L('admin_points_stage_pointorder');

        $array['app'] = L('admin_points_stage_app');

        return $array;

    }
}

